//
//  StoreRequest.swift
//  物料商行
//
//  Created by HaoDong Hong on 2017/9/2.
//  Copyright © 2017年 HaoDong Hong. All rights reserved.
//

import Alamofire
import SwiftyJSON

enum StoreRequest: RequestProtocol {
    var host: String {
        switch self {
        case .createSessionId:
            return "http://120.25.176.231:8000/"
        default:
            return "http://120.25.176.231:8000/seller-material/material/"
        }
    }
    
    
    //未来需要改掉的StoreSessionId
    case createSessionId
    
    
    /// 创建商店
    case store
    /// 申请认证成为卖家
    case createstore(alias: String, name: String, address: String, mainBusiness: String, foundTime: String, license: String, logo: String)
    /// 判断是否验证成功
    case authenticate
    /// 是否有商店
    case exist
    /// 编辑商店
    case edit(parameters: Parameters)
    /// 店员查看商店
    case find
    ///客户查看商店
    case visit
    
    
    /// 查看所有成员
    case allMembers
    
    /// 添加成员
    case addMember(phone: String, memberName: String, authority: Int)
    
    /// 修改成员信息
    case editMembers(name: String, authority: Int, id: Int)
    /*
     {
     "ids": [
     9,
     10,
     11
     ]

 */
    
    
    /// 删除成员
    case deleteMember(memberIds: [Int])
    
    
    var path: String {
        switch self {
        
        case .createSessionId:
            return "session/create"
            
        case .store:
            return "store"
        case .createstore(_,_,_,_,_,_,_):
            return "store/create"
        case .authenticate:
            return "store/authenticate"
        case .exist:
            return "store/exist"
        case .find:
            return "store/find"
        case .visit:
            return "store/visit"
        case.edit(_):
            return "store/edit"
            
        case .allMembers:
            return "member/find"
        case .addMember(_, _, _):
            return "member/add"
        case .deleteMember(_):
            return "member/delete"
        case .editMembers(_, _, _):
            return "member/edit"
        }
    }
    var bodyParams: Parameters {
        switch self {
            
        case .createSessionId:
            return ["userId": User.phoneNumber!, "value": "123"]
            
        case .store:
            return ["sessionId": Store.sessionID!]
        case .createstore(let alias, let name, let address, let mainBusiness, let foundTime, let license, let logo):
            return ["sessionId": Store.sessionID!, "alias": alias, "name": name, "address": address, "mainBusiness": mainBusiness, "foundTime": foundTime, "license": license, "logo": logo]
        case .authenticate:
            return ["sessionId": Store.sessionID!, "storeId": Store.storeId!]
        case .exist:
            return ["sessionId": Store.sessionID!]
        case .find:
            return ["sessionId": Store.sessionID!, "storeId": Store.storeId!]
        case .edit(let parameters):
            return parameters
        case .visit:
            return ["sessionId": Store.sessionID!, "storeId": Store.storeId!]
            
        case .allMembers:
            return ["sessionId": Store.sessionID!, "storeId": Store.storeId!]
        
        case .addMember(let phone, let memberName, let authority):
            return ["memberId": phone, "storeId": Store.storeId!, "sessionId": Store.sessionID!, "authority": authority, "memberName": memberName]
        case .deleteMember(let memberIds):
            let json = """
            {
                "ids": \(memberIds)
            }
            """
            return ["sessionId": Store.sessionID!, "memberIds": json, "storeId": Store.storeId!]
        case .editMembers(let name, let authority, let id):
            return ["name": name, "authority": authority, "sessionId": Store.sessionID!, "storeId": Store.storeId!, "id": id]
        
        }
        
    }
    var fullURL: URL {
        let str = self.host + self.path
        return URL(string: str)!
    }
}



